﻿using System.Collections.Generic;
using System.Configuration;

namespace Mbs.Configuration
{
    public class ParameterConfigurationElement:ConfigurationElement
    {
        private ConfigurationPropertyCollection dynamicProperties = new ConfigurationPropertyCollection();

        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                ConfigurationPropertyCollection baseprops = base.Properties;
                foreach (ConfigurationProperty dynprop in dynamicProperties)
                {
                    baseprops.Add(dynprop);
                }
                return baseprops;
            }
        }

        public IDictionary<string, string> Parameters
        {
            get
            {
                var map = new Dictionary<string, string>();
                foreach (ConfigurationProperty item in base.Properties)
                    map[item.Name] = this[item] as string;
                return map;
            }
            set
            {
                ;
            }
        }


        protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
        {
            ConfigurationProperty dynprop = new ConfigurationProperty(name, typeof(string), value);
            dynamicProperties.Add(dynprop);
            this[dynprop] = value; // Add the value to values bag

            return true;
        }

    }
}
